package com.sgxy.wmservice.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sgxy.commonutils.R;
import com.sgxy.wmservice.entity.WmOutputOrder;
import com.sgxy.wmservice.entity.WmStoreGoods;
import com.sgxy.wmservice.entity.vo.OutputOrderVo;
import com.sgxy.wmservice.entity.vo.StoreGoodsVo;
import com.sgxy.wmservice.service.WmOutputOrderService;
import com.sgxy.wmservice.service.WmStoreGoodsService;
import com.sgxy.wmservice.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/wmservice/wmoutputorder")
public class WmOutputOrderController {

    @Autowired
    private WmOutputOrderService wmOutputOrderService;
    @PostMapping("{page}/{limit}")
    public R index(@PathVariable Long page,
                   @PathVariable Long limit,
                   @RequestBody(required = false) WmOutputOrder wmOutputOrder){
        Page<OutputOrderVo> outputOrderPage = new Page<>(page,limit);
        wmOutputOrderService.selectPageVoList(outputOrderPage, wmOutputOrder);

        return R.ok().data("items",outputOrderPage.getRecords()).data("total",outputOrderPage.getTotal());
    }

    @GetMapping("getOutputOrderById/{id}")
    public R getOutputOrderById(@PathVariable String id){
        OutputOrderVo outputOrderVo = wmOutputOrderService.selectOneById(id);
        return R.ok().data("outputOrderVo",outputOrderVo);
    }
    @PostMapping("addOutputOrder")
    public R addOutputOrder(@RequestBody WmOutputOrder wmOutputOrder){
        wmOutputOrder.setOutputNo(OrderNoUtil.getOrderNo());
        wmOutputOrderService.addOutputOrder(wmOutputOrder);
        return R.ok();
    }
    @PostMapping("updateOutputOrder")
    public R updateOutputOrder(@RequestBody WmOutputOrder wmOutputOrder){
        wmOutputOrderService.updateOutputOrder(wmOutputOrder);
        return R.ok();
    }
    //删除
    @DeleteMapping("{id}")
    public R deleteOrders(@PathVariable String id){
        wmOutputOrderService.deleteById(id);
        return R.ok();
    }
}

